<?php

/**
 * 注册用户打卡管理
 * Enter description here ...
 * @author Admin
 *
 */
class PunchAction extends CommonAction{
	
	
	/**
	 * 打卡记录列表
	 * Enter description here ...
	 */
	public function index() {
		$data = Init_GP(array("start","end","name"));
		
		$punch = D('Punch');
		if (!empty($data)){
			if (!empty($data['start']) && !empty($data['end']))
			{
				$start_tmp = strtotime($data['start']);
				$end_tmp = strtotime($data['end']);
				$map['addtime']  = array('between',"{$start_tmp},{$end_tmp}");
			}
			if (!empty($data['name']))$map['name']=array('eq',$data['name']);
		}
		import("@.ORG.Page"); //导入分页类
		$count = $punch->where($map)->count();    //计算总数
		$p = new Page ($count,10);
		$punchdata=$punch->where($map)->limit($p->firstRow.','.$p->listRows)->order('id desc')->findAll();
		//分页条件写入
		foreach($data as $key=>$val) {
			$p->parameter   .=   "$key=".$val."&";
		}
		
		$page = $p->show ();
		$this->assign("page",$page);
		$this->assign("punchdata",$punchdata);
		$this->assign('down',$p->parameter);
		
		$this->display();
	}
	
	
	/**
	 * 导出数据
	 * Enter description here ...
	 */
	public function down(){
		$data = Init_GP(array("start","end","name"));
		
		$punch = D('Punch');
		if (!empty($data)){
			if (!empty($data['start']) && !empty($data['end']))
			{
				$start_tmp = strtotime($data['start']);
				$end_tmp = strtotime($data['end']);
				$map['addtime']  = array('between',"{$start_tmp},{$end_tmp}");
			}
			if (!empty($data['name']))$map['name']=array('eq',$data['name']);
			
		}
		$punchdata=$punch->where($map)->order('id desc')->findAll();
		
		$keynames = array(
			'id'=>'ID',
			'uid'=>'用户ID',
			'name'=>'用户名',
			'addtime'=>'打卡时间'
		);
		down_xls($punchdata, $keynames,'打卡日志_'.date("Y-m-d"));
	}
	
	
	
	
	public function add(){
		$this->error('操作错误');
	}
	
	public function edit(){
		$this->error('操作错误');
	}
	
	public function del(){
		$this->error('操作错误');
	}
	
	public function dels(){
		$this->error('操作错误');
	}
	
	public function insert(){
		$this->error('操作错误');
	}
	
	public function update(){
		$this->error('操作错误');
	}
	
}
?>